package com.ecdc.soexample;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;
import com.ecdc.annotation.BindViewUtils;
import com.ecdc.annotation.EcdcAnnotation;
import com.deep_tools.ecdc.R;
import utils.SharedpreferencesUtils;


public class LoginActivity extends Activity {
    @EcdcAnnotation.EcdcAnno(R.id.login)
    private TextView login;




    @EcdcAnnotation.EcdcAnno(R.id.dd_activity_login)
    private TextView dd_activity_login;




    @Override
    public void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        try {
            BindViewUtils.getInstance().initEcdcAnnotationActivity(this,this);
        } catch (IllegalAccessException e) {
            e.printStackTrace();

        }
        onClickL();
//        if(Build.VERSION.SDK_INT >= 23){
//            String[] mPermissionList = new String[]{
//                    Manifest.permission.WRITE_EXTERNAL_STORAGE,
//                    Manifest.permission.READ_PHONE_STATE,
//                    Manifest.permission.READ_EXTERNAL_STORAGE};
//            this.requestPermissions(mPermissionList, 123);
//        }
        checkPermission();

//        Intent intent = new Intent(this, BluetoothLeService2.class);
//        startService(intent);
//        startService(new Intent(this, NotificationCollectorMonitorService.class));


        String ANDROID_ID = Settings.System.getString(getContentResolver(), Settings.System.ANDROID_ID);

//        Toast.makeText(this, ""+ANDROID_ID, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onResume() {
        super.onResume();
//        userName_activity_login.setText(SharedpreferencesUtils.getCheckSendDataUtilsInstance().getUser(this));
//        password_activity_login.setText(SharedpreferencesUtils.getCheckSendDataUtilsInstance().getPassword(this));

    }

    /**
     * 点击事件
     */
    private void onClickL(){
        dd_activity_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
//Intent intent = new Intent(Intent.ACTION_VIEW,uri);
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse("https://www.touchelx.com");
                intent.setData(content_url);
                startActivity(intent);
            }
        });




        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent(LoginActivity.this,PairWatchActivity.class);
                startActivity(intent);
                LoginActivity.this.finish();

//                final String userName=userName_activity_login.getText().toString();
//                final String password=password_activity_login.getText().toString();
//                if(userName==null||userName.equals("")||password==null||password.equals("")){
//                    ToastUtils.getToastUtilsInstance().toastCenterStrip("user name and password cannot be empty!!!",LoginActivity.this, Color.WHITE);
//
//                }else{
//                    ToastUtils.getToastUtilsInstance().displayProgressDialog(LoginActivity.this);
//                    HttpTools httpTools=new HttpTools();
//                    httpTools.setDeligate(new HttpTools.HttpToolsCallBack() {
//                        @Override
//                        public void successHttpUtilsCallBack(String data) {
//                            ResultData2 mResultData2=JSON.parseObject(data, ResultData2.class);
//                            if(mResultData2.result.equals("1")){
//                                SharedpreferencesUtils.getCheckSendDataUtilsInstance().saveUserAndPassword(userName,password,LoginActivity.this);
//
//                                Intent intent=new Intent(LoginActivity.this,PairWatchActivity.class);
//                                startActivity(intent);
//                                LoginActivity.this.finish();
//                            }else {
//                                ToastUtils.getToastUtilsInstance().toastCenterStrip(mResultData2.data,LoginActivity.this, Color.WHITE);
//
//                            }
//                            ToastUtils.getToastUtilsInstance().dismissProgressDialog();
//                        }
//
//                        @Override
//                        public void errorHttpUtilsCallBack(String data) {
//                            ToastUtils.getToastUtilsInstance().toastCenterStrip(data,LoginActivity.this, Color.WHITE);
//                            ToastUtils.getToastUtilsInstance().dismissProgressDialog();
//                        }
//                    });
//                    httpTools.login(userName,password);
//
//
//                }


            }
        });


    }


    /**
     * 权限确认
     */
    private void checkPermission(){
        String[] PERMISSIONS = new String[]{
                Manifest.permission.BLUETOOTH,
                Manifest.permission.BLUETOOTH_ADMIN,
                Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.INTERNET,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.READ_EXTERNAL_STORAGE,};
        if(Build.VERSION.SDK_INT >= 23){
            for(int i=0;i<PERMISSIONS.length;i++){
                int hasPermission = checkSelfPermission(PERMISSIONS[i]);
                //没有授权
                if (hasPermission != PackageManager.PERMISSION_GRANTED) {
                    //进行授权提示 1006为返回标识
                    requestPermissions(new String[]{PERMISSIONS[i]},
                            1006);

                }
            }
        }

    }


    @Override
    public void onRequestPermissionsResult(int requestCode,  String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//        if(Build.VERSION.SDK_INT >= 23){
//            for(int i=0;i<PERMISSIONS.length;i++){
//                int hasPermission = checkSelfPermission(PERMISSIONS[i]);
//                //没有授权
//                if (hasPermission != PackageManager.PERMISSION_GRANTED) {
//                    //进行授权提示 1006为返回标识
//                    requestPermissions(new String[]{PERMISSIONS[i]},
//                            1006);
//
//                }
//            }
//        }


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

}
